//反转链表
//https://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca?tpId=295&tqId=23286&ru=/exam/oj&qru=/ta/format-top101/question-ranking&sourceUrl=%2Fexam%2Foj
/*
struct ListNode {
	int val;
	struct ListNode *next;
	ListNode(int x) :
			val(x), next(NULL) {
	}
};*/

class Solution {
public:
	ListNode* ReverseList(ListNode* pHead){
		//处理空链表
		if(pHead == NULL)
			return NULL;
		ListNode* cur = pHead;
		ListNode* pre = NULL;
		while(cur != NULL){
			//断开链表，要记录后续一个
			ListNode* temp = cur->next;
			//当前的next指向前一个
			cur->next = pre;
			//前一个更新为当前
			pre = cur;
			//当前更新为刚刚记录的后一个
			cur = temp;
		}
		return pre;
	}
};